1. Field of the Invention
The invention relates in general to data encoding and decoding methods and computer readable medium thereof, and more particularly to a data encoding method and a decoding method which utilize specific character replacement and computer readable medium thereof.
2. Description of the Related Art
In the course of data processing, some values are defined to have specific mechanism. For example, in C Language, a string is a zero-terminated string, that is, the string is ended with such a character NULL (“\0”), wherein the binary value of the character NULL is “0”. Thus, during the process of converting a binary data into a string, the string is split and is determined to terminate when the bit whose binary value is “0” is encountered. However, as “0” usually occurs in the binary data stream, during the process of converting a binary data into a string, the string will be inappropriately split and the data following the character being split will be missed.
To avoid the string being split, many data encoding methods have been provided. Referring to FIG. 1, an example of simulated diagram of a data executed by a conventional data encoding method is shown. The values of the 9 bytes in the data A before encoding are “0”, “0 ”, “1”, “2”, “0”, “3”, “5”, “0”, “4”, respectively. The values of the 10 bytes in the encoded data e(A) are “5”, “1”, “2”, “5”, “1”, “2”, “3”, “5”, “4”, respectively. The 1-st byte in the data e(A) denotes the number of “0” in the data A before encoding plus 1, that is, “5” in this example. The 2-nd to the 5-th bytes in the data e(A) record the position of the bytes whose values are “0”. The 6-th to the 10-th bytes of the data e(A) sequentially record the non-“0” values of the bytes in the data A.
However, in the above method which records the position of the bytes whose values are “0”, an array is generated during the process of decoding the data e(A) into the data A, and the 1-st byte in data e(A) is read so as to obtain the number of the bytes whose value are “0” in the data A. Following that, the 2-nd to the 5-th byte in the data e(A) are read so as to obtain the position of the bytes whose values are “0” in the data A. Next, the values of the 6-th to the 10-th bytes in the data e(A) are sequentially written to the position of the bytes whose values are non-“0” in the data A. Thus, the complexity of decoding is increased and the efficiency of decoding is decreased.